package com.xiao.common.exception;

import com.xiao.common.util.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author xiaoxiaoping
 * @Date 2020/3/10 10:15
 * @Version 1.0
 */
@RestControllerAdvice
public class DefaultExceptionHandler {
    private  final Logger logger = (Logger) LoggerFactory.getLogger(this.getClass());

//    @ExceptionHandler(value = Exception.class)
//    public ResultUtil serverError(Exception e) {
//        String errMsg = "";
//        if (e instanceof NullPointerException) {
//            errMsg = "发生空指针异常";
//        } else if (e instanceof RuntimeException) {
//            errMsg = "发生运行时异常";
//        } else {
//            errMsg = e.getMessage();
//        }
//        logger.error("############" + errMsg + "############", e);
//        return ResultUtil.FAIL(errMsg,null);
//    }

    @ExceptionHandler(value = HisExecption.class)
    public ResultUtil paramError(HisExecption e) {
        logger.info("############" + e.getMsg() + "############");
        return new ResultUtil(Integer.valueOf(e.getCode()),"",null,e.getMsg());
    }
}
